const { Tab } = require('../../assets/libs/zanui/index');

var app = getApp();
Page(Object.assign({}, Tab, {
	data: {
		isHidden: true,//评价弹窗控制窗
		population: 0, // 服务态度评分点数初始值
		distribution: 0,// 准时率评分点数初始值
		evaluateContent: '',//评价文字内容
		currentId: 0,//当前要评论的订单id
		
		cdnUrl: '',
		bannerList: [],
		archivesList: [],
		loading: false,
		nodata: false,
		nomore: false,
		tab: {
			list: [],
			selectedId: '0',
			scroll: true,
			height: 44
		},
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#FFFFFF',
		show: true,
		animated: false,
		back: true,
		title: "我的订单",
		
		/* 订单筛选 */
		status: -1,
		orderList: []
	},
	/*跳转至详情页*/
	goorderdetail (e) {
		wx.navigateTo({
			url: e.currentTarget.dataset.url
		})
	},
	callphone (e) {
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.mobile
		})
	},
	/**
	 * 点击tab切换
	 */
	swichNav: function (e) {
		var that = this;
		if ( that.data.status===e.target.dataset.status ) {
			return false;
		} else {
			that.setData({
				status: e.target.dataset.status
			})
		}
		that.orderList(that.data.status);
	},
	orderList: function (status) {
		var that = this;
		app.request('/addons/cms/wxapp.user/orderList', { status: status }, function (data, ret) {
			that.setData({
				orderList: data
			});
		}, function (data, ret) {
			console.log(ret);
			app.error('服务器错误');
		});
	},
	onLoad: function () {
		var that = this;
		that.setData({
			cdnUrl: app.cdnUrl
		});
	},
	onShow: function () {
		this.orderList(-1);//获取订单列表 -1为默认全部订单
		var page = getCurrentPages();
		var prevpage = page[page.length - 2]; //上一个页面对象
		var path = prevpage.route;
	},
	onPullDownRefresh: function () {
		this.orderList(this.data.status);
	},
	onReachBottom: function () {
	},
	
	onShareAppMessage: function () {
		return {
			title: '',
			desc: '',
			path: '/page/index/index'
		}
	},
	/* 弹窗 */
	showMd: function (e) {
		var that = this;
		var id = e.currentTarget.dataset.id;
		that.setData({
			isHidden: false,//显示模态框，
			currentId: id
		})
	},
	hiddenMd: function () {
		this.setData({
			isHidden: true,//隐藏模态框
			population: 0, // 服务态度评分点数初始值
			distribution: 0,// 准时率评分点数初始值
			evaluateContent: '',//评价文字内容
			currentId: 0//当前要评论的订单id
		})
	},
	//点击准时率评价
	bindDistribution: function (event) {
		var that = this;
		var distribution = that.data.distribution;
		let datatype = event.currentTarget.dataset.type;
		let index = event.currentTarget.dataset.index;
		index = index + 1
		if ( datatype==1 ) {
			distribution = index;
		} else if ( datatype==2 ) {
			distribution = distribution + index
		}
		that.setData({
			distribution: distribution
		})
	},
	//点击服务态度评价
	bindPopulation: function (event) {
		var that = this;
		var population = that.data.population;
		let datatype = event.currentTarget.dataset.type;
		let index = event.currentTarget.dataset.index;
		index = index + 1
		if ( datatype==1 ) {
			population = index;
		} else if ( datatype==2 ) {
			population = population + index
		}
		that.setData({
			population: population
		})
	},
	/* 订单评价 */
	evaluate: function () {
		var that = this;
		var subData = {
			punctually: that.data.distribution,//准时率评分点数
			serviceAttitude: that.data.population,//服务态度评分点数
			evaluateContent: that.data.evaluateContent,
			id: that.data.currentId
		}
		app.request('/addons/cms/wxapp.recovery/orderEvaluate', subData, function (data, ret) {
			that.setData({
				isHidden: true//隐藏模态框
			})
			app.success(ret.msg);
			that.orderList(that.data.status);
		}, function (data, ret) {
			app.error(ret.msg);
		});
	},
	evaluateContentChange: function (e) {
		var that = this;
		var value = e.detail.value;
		that.setData({
			evaluateContent: value
		})
	}
}))
